﻿
var equipmentname = null;
var equimentStatus = null;
var description = null;
var addBtn = null;
var backBtn = null;


$(function(){
    equipmentname = $("#equipmentname");
    equimentStatus = $("#equimentStatus");
    description = $("#description");
    addBtn = $("#add");
    backBtn = $("#back");
    //初始化的时候，要把所有的提示信息变为：* 以提示必填项，更灵活，不要写在页面上
    equipmentname.next().html("*");
    equimentStatus.next().html("*");
    description.next().html("*");

    /*
     * 验证
     * 失焦\获焦
     * jquery的方法传递
     */

    equipmentname.bind("focus",function(){
        validateTip(equipmentname.next(),{"color":"#666666"},"* 器材名称不能为空",false);
    }).bind("blur",function(){
        if(equipmentname.val() != null){
            validateTip(equipmentname.next(),{"color":"green"},imgYes,true);
        }else{
            validateTip(equipmentname.next(),{"color":"red"},imgNo+" 器材名称不能为空",false);
        }

    });

    equimentStatus.bind("focus",function(){
        validateTip(equimentStatus.next(),{"color":"#666666"},"* 器材状态必须为可使用或在维护",false);
    }).bind("blur",function(){
        if(equimentStatus.val() != null ){
            validateTip(equimentStatus.next(),{"color":"green"},imgYes,true);
        }else{
            validateTip(equimentStatus.next(),{"color":"red"},imgNo + " 器材状态不能为空",false);
        }
    });

    description.bind("focus",function(){
        validateTip(description.next(),{"color":"#666666"},"* 请输入描述",false);
    }).bind("blur",function(){
        if(description.val() != null){
            validateTip(description.next(),{"color":"green"},imgYes,true);
        }else{
            validateTip(description.next(),{"color":"red"},imgNo + " 描述为空，请重新输入",false);
        }
    });
    addBtn.bind("click",function(){
        if(equipmentname.attr("validateStatus") != "true"){
            equipmentname.blur();
        }else if(equimentStatus.attr("validateStatus") != "true"){
            equimentStatus.blur();
        }else if(description.attr("validateStatus") != "true"){
            description.blur();
        }else{
            if(confirm("是否确认提交数据")){
                $("#equipmentForm").submit();
            }
        }
    });

    backBtn.on("click",function(){
        if(referer != undefined
            && null != referer
            && "" != referer
            && "null" != referer
            && referer.length > 4){
            window.location.href = referer;
        }else{
            history.back(-1);
        }
    });
});